#include "common.h"

#include <dirent.h>
#include <stdio.h>
#include <iostream>
#include <fstream>

bool getdir (std::string dir, std::vector<std::string> &files) {
    DIR *dp;
    struct dirent *dirp;
    if((dp  = opendir(dir.c_str())) == NULL) {
        std::cout << "Error(" << 1 << ") opening " << dir << std::endl;
        return true;
    }

    while ((dirp = readdir(dp)) != NULL) {
        files.push_back(std::string(dirp->d_name));
    }
    closedir(dp);
    return false;
}

bool fileExists(const char *fname) {
	return std::ifstream(fname) != NULL;
}

void printHelp() {
	printf("\nUSAGE:\n");
	printf("1) lm calibrate [OPTIONS]\n");
	printf("2) lm learn [OPTIONS] <symbol>\n");
	printf("3) lm test [OPTIONS] <test_file>\n\n");
	printf("4) lm calc [OPTIONS]\n\n");
	printf("5) lm cc [OPTIONS]\n\n");

	printf("COMMON OPTIONS\n");
	printf("\t--help - show this info\n");
	printf("\t--source=<file> - use <file> as a video source\n");
	printf("\t--conf=<config_file> - use configuration file <config_file>\n");
	printf("\t--sizex=<size> - set image size x\n");
	printf("\t--sizey=<size> - set image size y\n");
	printf("\t--camid=<number> - use camera #number\n\n");


	printf("ACTION SPECIFIC OPTIONS\n\n");
	
	printf("1) calibrate\n");
	printf("\t--manual - manual calibration\n");
	printf("\t--auto - automatic calibration (default)\n\n");

	printf("2) learn\n");
	printf("\t--base=<baseDir> - use base directory <baseDir>\n\n");

	printf("3) test\n");
	printf("\t--base=<baseDir> - use base directory <baseDir>\n\n");

	printf("4) calc\n");
	printf("\t--base=<baseDir> - use base directory <baseDir>\n\n");

	printf("5) cc\n");
	printf("\t--field=<size> - set numer of squares on the field\n");
	printf("\t--win=<num> - set numer of successively figures for victory\n");
	printf("\t--base=<baseDir> - use base directory <baseDir>\n\n");
}

